import 'package:flutter/material.dart';
import 'package:hktk_app/ienum/home/column_type_enum.dart';
import 'package:hktk_app/ienum/my/rank_type_enum.dart';
import 'package:hktk_app/model/home/column_model.dart';
import 'package:hktk_app/pages/mine/child/note_expandable_page.dart';
import 'package:hktk_app/pages/mine/child/view_page.dart';
import 'package:hktk_app/util/view_util.dart';
import 'package:hktk_app/widget/mine/my_tab_bar_widget.dart';
import 'package:hktk_app/widget/page_title_widget.dart';

final List<ColumnModel> _tabList = [
  ColumnModel(name: "最新笔记", type: ColumnTypeEnum.zx),
  ColumnModel(name: "章节", type: ColumnTypeEnum.chapterPractice),
  ColumnModel(name: "试卷", type: ColumnTypeEnum.paperLibrary),
];

/// 我的笔记页面
class MyNodePage extends StatefulWidget {
  const MyNodePage({super.key});

  @override
  State<MyNodePage> createState() => _MyNodePageState();
}

class _MyNodePageState extends State<MyNodePage> with TickerProviderStateMixin {
  /// tab控制器
  late TabController _tabController;

  @override
  void initState() {
    super.initState();
    debugPrint("myNodePage 页面 -> initState 方法执行 ===> ");
    debugPrint("");
    _tabController = TabController(length: _tabList.length, vsync: this);
  }

  @override
  void dispose() {
    super.dispose();
    debugPrint("myNodePage 页面 -> dispose 方法执行 ===> ");
    debugPrint("");
    _tabController.dispose();
  }

  @override
  Widget build(BuildContext context) {
    debugPrint("myNodePage 页面 -> build 方法执行 ===> ");
    debugPrint("");
    return Scaffold(
      backgroundColor: colorWhite2,
      body: Column(
        children: [
          PageTitleWidget(
            name: "我的笔记",
            pageContext: context,
          ),
          MyTabBarWidget(
            tabController: _tabController,
            list: _tabList,
          ),
          Expanded(
            child: TabBarView(
              controller: _tabController,
              children: _viewItems(),
            ),
          ),
        ],
      ),
    );
  }

  /// 内容显示组件
  _viewItems() {
    List<Widget> pageList = [];
    for (ColumnModel value in _tabList) {
      if (value.type == ColumnTypeEnum.zx) {
        pageList.add(ViewPage(tabModel: value, type: RankTypeEnum.note));
      } else {
        pageList.add(NoteExpandablePage(tabModel: value));
      }
    }
    return pageList;
  }
}
